s = "  hello world  "
def reverseWords(s: str):
    print(s.split(" "))
    s_segment=s.split(' ')
    length=len(s_segment)
    ans=""
    for i in range(length):
        if s_segment[length-i-1]!="":
            ans+=s_segment[length-i-1]+" "

    return ans[:len(ans)-1]



print(reverseWords(s))
